﻿@using Abp.Application.Services.Dto;
@using FwProject.Settlement
@using FwProject.Settlement.Dto
@using FwProject.Core.SettlementInfoModel
@using FwProject.Distribution.Dto
@using FwProject.Authorization
@model Tuple<SettlementReceivableDto, List<DistributionDto>>
@{
    ViewBag.Title = "收据[" + Model.Item1.CreationNumber + "]";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }

        .checked {
            position: absolute;
            top: 3px;
            left: 220px;
            height: 87px;
            width: 141px;
            background: url('/images/checked.gif') left top no-repeat;
            z-index: 9999;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    <a class="btn btn-primary btn-xs" href="@Url.Action("ExaminePrint",new { id=Model.Item1.SettlementId})" target="view_window">打印</a>
                </div>
            </div>
            <div class="ibox-content" style="height:700px">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" asp-controller="Settlement" asp-action="EditDiscountprice" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback">
                        <input type="hidden" name="id" value="@Model.Item1.SettlementId" />
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">单号：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationNumber" class="input-sm form-control" value="@Model.Item1.CreationNumber" readonly="readonly">
                                </div>
                                @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                                {
                                    <div class="checked" id="check_icon"></div>
                                }
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">日期：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationTime" class="input-sm form-control" value="@Model.Item1.CreationTime.ToString("yyyy-MM-dd")" readonly="readonly">
                                </div>
                            </div>
                            @*<div class="col-md-4">
                                <label class="control-label col-md-3">经办人：</label>
                                <div class="input-group">
                                    <input type="text" name="AgentPeoper" class="input-sm form-control" value="@Model.Item1." readonly="readonly">
                                </div>
                            </div>*@
                        </div>
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">餐厅：</label>
                                <div class="input-group">
                                    <input type="text" name="RestaurantName" class="input-sm form-control" value="@Model.Item1.RestaurantName" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">收款司机：</label>
                                <div class="input-group">
                                    <input type="text" name="DriverName" class="input-sm form-control" value="@Model.Item1.DriverName" readonly="readonly">
                                </div>
                            </div>
                        </div><hr />
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">应收金额（￥）：</label>
                                <div class="input-group">
                                    <input type="text" name="TotalPrice" id="TotalPrice" class="input-sm form-control" value="@Model.Item1.TotalPrice" readonly="readonly">
                                </div>
                            </div>
                            @if (IsGranted(PermissionNames.Settlement_Edit) && Model.Item1.ExamineStatus == ExamineStatus.未审核)
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">优惠金额（￥）：</label>
                                    <div class="input-group">

                                        <input type="text" name="Discountprice" id="Discountprice" oninput="setPrice(this)" class="input-sm form-control" value="@Model.Item1.Discountprice">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">优惠金额（￥）：</label>
                                    <div class="input-group">
                                        <input type="text" name="Discountprice" class="input-sm form-control" value="@Model.Item1.Discountprice" readonly="readonly">
                                    </div>
                                </div>
                            }

                            <div class="col-md-4">
                                <label class="control-label col-md-3">实收金额（￥）：</label>
                                <div class="input-group">
                                    <input type="text" name="Actualprice" id="Actualprice" class="input-sm form-control" value="@Model.Item1.Actualprice" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div id="data_list">
                            <div>
                                @if (Model.Item2.Count == 0)
                                {
                                    <h4>暂无数据</h4>
                                }
                                else
                                {
                                    <table class="table table-bordered table-hover table-rowselected">
                                        <thead>
                                            <tr>
                                                <th>配送单号</th>
                                                <th>配送日期</th>
                                                <th>应收金额（￥）</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach (var item in Model.Item2)
                                            {
                                                <tr>
                                                    <td>@item.CreationNumber</td>
                                                    <td>@item.CreationTime.ToString("yyyy-MM-dd hh:mm:ss")</td>
                                                    <td>@item.TotalPrice</td>
                                                </tr>
                                            }
                                        </tbody>
                                    </table>
                                }
                            </div>
                        </div><br />
                        @if (Model.Item1.ExamineStatus == ExamineStatus.未审核)
                        {
                            <div class="ibox-tools">
                                @*<a href="/Settlement/EditStatus?id=@Model.Item1.SettlementId" class="btn btn-primary btn btn-sm">确认审核</a>*@
                                <button type="submit" class="btn btn-primary btn btn-sm">确认审核</button>
                            </div>
                        }
                    </form>
                </div>


            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script>
        function setPrice(obj) {
            var TotalPrice = parseFloat($('#TotalPrice').val());
            var Discountprice = parseFloat($('#Discountprice').val());
            if (Discountprice < 0) {
                $('#Discountprice').val(0.00);
                Discountprice = 0.00;
            }
            $('#Actualprice').val(parseFloat(TotalPrice - Discountprice));
        }
        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                window.location.reload();
            }, successInfo);
        }
    </script>
}